package cn.zhl.algorithm._3_并查集.impl;

/**
 * @program: demos
 * @description: 基于高度的优化，合并的时候查看两边的根节点下面子元素的高度
 * @author: 刘振华
 * @create: 2020-06-11 19:00
 **/
public class QuickUnionHeightCompress extends QuickUnionHeight {
	public QuickUnionHeightCompress(int capacity){
		super(capacity);
	}

	@Override
	public int find(int v) {
		rangeCheck(v);
		if(parent[v] != v){
			parent[v] = find(parent[v]);
		}
		return parent[v];
	}
}
